package com.dream.keigezhushou.Activity.kege.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dream.keigezhushou.R;

/**
 * Created by Administrator on 2017/3/20.
 * 合唱排行榜适配器
 */
public class SingRankingAdapter extends BaseAdapter {

    private Context mContext;
    private int currIndex;
    int c = 10;
    public ItemOnClickListening itemOnClickLinister = null;
    private int postion;

    public void setItemOnClickListening(ItemOnClickListening listening) {
        this.itemOnClickLinister = listening;
    }

    public SingRankingAdapter(Context context, int currIndex) {
        this.mContext = context;
        this.currIndex = currIndex;
    }

    @Override
    public int getCount() {
        return c;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        postion = i;
        ProHolder mHolder = null;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_singing_ranking, null);
            mHolder = new ProHolder();
            mHolder.keGeLinear = (LinearLayout) view.findViewById(R.id.item_ranking_linear);
            mHolder.giftImage = (ImageView) view.findViewById(R.id.item_ranking_gift);
            mHolder.rankingStateTv = (TextView) view.findViewById(R.id.item_ranking_state);
            view.setTag(mHolder);
        } else {
            mHolder = (ProHolder) view.getTag();
        }

        if (currIndex == 0) {
            mHolder.rankingStateTv.setVisibility(View.GONE);
        }


        if (i == 0) {
            mHolder.giftImage.setImageResource(R.drawable.gift_list2);
        } else if (i == 1) {
            mHolder.giftImage.setImageResource(R.drawable.gift_list3);
        } else if (i == 2) {
            mHolder.giftImage.setImageResource(R.drawable.gift_list1);
        } else {
            mHolder.giftImage.setVisibility(View.INVISIBLE);
        }
        mHolder.keGeLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemOnClickLinister != null) {

                    itemOnClickLinister.itemClick(postion);
                }
            }
        });

        mHolder.rankingStateTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemOnClickLinister != null) {
                    itemOnClickLinister.itemClick(postion);
                }


            }
        });


        return view;
    }


    class ProHolder {

        private LinearLayout keGeLinear;
        private ImageView giftImage;
        private TextView rankingStateTv;

    }


    public interface ItemOnClickListening {
        public void itemClick(int postion);

    }

}